﻿using UnityEngine;
using System.Collections;
using AssetLoad;

namespace Story
{

    public class StoryDialogHero : MonoBehaviour
    {
        public UISprite body;
        public UISprite face;

        public string faceName;

        public float pos;

        Dict.DataModel.TableStoryDialogHero data;
        StoryDialogManager manager;

        private int order = 0;
        public void SetOrder(int order)
        {
            this.order = order;
            body.depth = 10 + order * 2;
            face.depth = 11 + order * 2;
        }

        public int GetOrder()
        {
            return order;
        }

        public void SetFace(string faceName)
        {
            face.spriteName = faceName;
            if (face.atlas != null && face.atlas.GetSprite(faceName) == null) {
                face.spriteName = "normal";
            }
            face.MakePixelPerfect(); 
        }

        public void SetFocus(bool focus)
        {
            if (focus)
            {
                body.color = Color.white;
                face.color = Color.white;
            }
            else
            {
                body.color = new Color(0.5f, 0.5f, 0.5f, 1);
                face.color = new Color(0.5f, 0.5f, 0.5f, 1);
            }
        }

        public void Show()
        {
            gameObject.SetActive(true);
            face.atlas = manager.GetUIAtlasFromCache(data.faceAtlas);
            body.atlas = manager.GetUIAtlasFromCache(data.bodyAtlas);
            face.MakePixelPerfect();
            body.MakePixelPerfect();
        }
        public void Hide()
        {
            gameObject.SetActive(false);
        }

        public void Init(string actorId, StoryDialogManager manager)
        {
            this.manager = manager;
            data = Dict.Blo.DictStoryBlo.GetTableStoryDialoHero(actorId);
        }

        public string GetCurrentDialoyHeroId() {
            if (data != null)
                return data.id;
            return "";
        }

        public void Clear() {
            body.atlas = null;
            face.atlas = null;
            data = null;
        }

    }

}


